package com.onefinger.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.onefinger.aspect.Cache;
import com.onefinger.aspect.Uncache;
import com.onefinger.domain.Request;
import com.onefinger.repository.GenericRepository;

public class RequestService implements IRequestService {

	@Autowired
	GenericRepository<Request> genericRepository; 

	@Cache(cacheKey="requests", expireTime=0)
	public List<Request> list() {
		return genericRepository.getList(Request.class);
	}

	
	@Uncache(cacheKey="requests")
	public boolean save(Request request) {
		try {
			genericRepository.save(request);
		} catch (Exception e) {
			
			return false;
		}
		return true;
	}

	@Uncache(cacheKey="requests")
	public boolean remove(Request request) {
		try {
			genericRepository.remove(request);
		} catch (Exception e) {
			
			return false;
		}
		return true;
	}


	@Override
	public List<Request> listBySessionId(Long sessionId) {
		return genericRepository.getListCondicional(Request.class, "sessionId", sessionId);
	}

	
}
